package com.lz.football.module.activity.Thefirstcharge
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.message.http.JsClient;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	import common.BaseView.GoodItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	/**
	 *首充 
	 * @author Administrator
	 * 
	 */	
	public class ThefirstchargeView extends BaseView implements IActivity
	{
		/**
		 *充值按钮 
		 */
		private var topupBtn:SimpleButton;
		/**
		 *领取状态  
		 */
		private var status:MovieClip;
		private var _itemVec:Vector.<GoodItem>;
		public function ThefirstchargeView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.theFirstchargeView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.theFirstchargeBg;
			isDrag = true;
			isCloseBtn = true;
			
			_viewHeight = symbolSkin.height;
			_viewWidth  =symbolSkin.width;
			moveClose(_viewWidth - 35,28);
			topupBtn = symbolSkin.topupBtn;
			status = symbolSkin.status;
			status.gotoAndStop(1);
			onResizeHandler();
			addEvtListener();
			initItem();
			
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			topupBtn.addEventListener(MouseEvent.CLICK,onTopupHandler);
		}
		
		protected function onTopupHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			JsClient.recharge();
		}
		
		/**
		 *初始化 
		 * 
		 */
		private function initItem():void
		{
			var arr:Array = AppData.getInstance().activityDatemanager.theFirstCharge;
			var item:GoodItem;
			_itemVec = new Vector.<GoodItem>;
			var len:int = arr.length;
			for(var i:int = 0;i < len;i++)
			{
				item = new GoodItem();
				item.initUI();
				item.data = AppData.getInstance().goodsManager.getGoodsByTypeAndId(arr[i][1],arr[i][0]);;
				this.addChild(item);
				item.x = 85 + (92) * i;
				item.y = 145;
				_itemVec.push(item);
			}
			if(AppData.getInstance().clubDatamanager.clubInfo.firstpay == 1)//已领取
			{
				status.gotoAndStop(2);
			}else
			{
				status.gotoAndStop(1);
			}
		}
	
		public function baseinformation($obj:Object):void
		{
		}
		
		public function award($obj:Object):void
		{
		}
		/**
		 *关闭按钮 
		 * @param event
		 * 
		 */		
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE,null,true));
		}
		override public function removeEvtListener():void
		{
			topupBtn.removeEventListener(MouseEvent.CLICK,onTopupHandler);
			super.removeEvtListener();
		}
		override public function destroyView():void
		{
			
			while(_itemVec.length)
			{
				_itemVec.pop().destroyView();
			}
			_itemVec = null;
			removeEvtListener();
			super.destroyView();
		}
	}
}